using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Threading.Tasks;
using System.Collections.ObjectModel;

namespace TaskClient4.SystemService
{
    public partial class SystemServiceClient
    {

        public Task DoWorkTaskAsync()
        {
            return Task.Factory.FromAsync(this.Channel.BeginDoWork, this.Channel.EndDoWork, null);
        }
        public void DoWork()
        {
            var task = DoWorkTaskAsync();
            task.Wait();
        }

        public Task<DateTime> GetSerivceTimeTaskAsync()
        {
            return Task<DateTime>.Factory.FromAsync(this.Channel.BeginGetSerivceTime, this.Channel.EndGetSerivceTime, null);
        }
        public DateTime GetSerivceTime()
        {
            var task = GetSerivceTimeTaskAsync();
            task.Wait();
            return task.Result;
        }

        public Task<String> SayHiToTaskAsync(String name)
        {
            return Task<String>.Factory.FromAsync(this.Channel.BeginSayHiTo, this.Channel.EndSayHiTo, name, null);
        }
        public String SayHiTo(String name)
        {
            var task = SayHiToTaskAsync(name);
            task.Wait();
            return task.Result;
        }

        public Task<Decimal> GetNumTaskAsync(Decimal num)
        {
            return Task<Decimal>.Factory.FromAsync(this.Channel.BeginGetNum, this.Channel.EndGetNum, num, null);
        }
        public Decimal GetNum(Decimal num)
        {
            var task = GetNumTaskAsync(num);
            task.Wait();
            return task.Result;
        }

    }
}
namespace TaskClient4.UserService
{
    public partial class UserServiceClient
    {

        public Task<UserInfo> CreateUserTaskAsync(UserInfo user)
        {
            return Task<UserInfo>.Factory.FromAsync(this.Channel.BeginCreateUser, this.Channel.EndCreateUser, user, null);
        }
        public UserInfo CreateUser(UserInfo user)
        {
            var task = CreateUserTaskAsync(user);
            task.Wait();
            return task.Result;
        }

        public Task UpdateUserTaskAsync(UserInfo user)
        {
            return Task.Factory.FromAsync(this.Channel.BeginUpdateUser, this.Channel.EndUpdateUser, user, null);
        }
        public void UpdateUser(UserInfo user)
        {
            var task = UpdateUserTaskAsync(user);
            task.Wait();
        }

        public Task DeleteTaskAsync(String id)
        {
            return Task.Factory.FromAsync(this.Channel.BeginDelete, this.Channel.EndDelete, id, null);
        }
        public void Delete(String id)
        {
            var task = DeleteTaskAsync(id);
            task.Wait();
        }

        public Task<ObservableCollection<UserInfo>> GetAllTaskAsync()
        {
            return Task<ObservableCollection<UserInfo>>.Factory.FromAsync(this.Channel.BeginGetAll, this.Channel.EndGetAll, null);
        }
        public ObservableCollection<UserInfo> GetAll()
        {
            var task = GetAllTaskAsync();
            task.Wait();
            return task.Result;
        }

        public Task<UserInfo> GetUserByIdTaskAsync(String id)
        {
            return Task<UserInfo>.Factory.FromAsync(this.Channel.BeginGetUserById, this.Channel.EndGetUserById, id, null);
        }
        public UserInfo GetUserById(String id)
        {
            var task = GetUserByIdTaskAsync(id);
            task.Wait();
            return task.Result;
        }

    }
}
